﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.PoseEditor.CApKinPoseEditorUtils
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.JointJog;
using System;
using System.Windows.Forms;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.PoseEditor;

internal class CApKinPoseEditorUtils
{
  internal static void JumpToPose(TxPose pose)
  {
    ITxDevice device = pose.Device;
    if (new TxDevicePoseData(device, device.CurrentPose).Equals((object) new TxDevicePoseData(device, pose.PoseData)))
      return;
    device.CurrentPose = pose.PoseData;
    TxApplication.RefreshDisplay();
  }

  internal static void MoveToPose(TxPose pose)
  {
    ITxDevice device = pose.Device;
    if (new TxDevicePoseData(device, device.CurrentPose).Equals((object) new TxDevicePoseData(device, pose.PoseData)) || TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded() && TxApplication.ActiveDocument.SimulationPlayer.IsSimulationRunning())
      return;
    new CApKinPoseEditorMoveToPose(device, pose).MoveToPose();
  }

  internal static void UpdatePose(TxPose pose)
  {
    ITxDevice device = pose.Device;
    if (TxMessageBox.Show(string.Format(PoseEditorStringTable.UPDATE_CONFIRMATION, (object) pose.Name), PoseEditorStringTable.CMD_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
      return;
    using (TxPoseData currentPose = device.CurrentPose)
      pose.PoseData = currentPose;
  }

  internal static CUiKinJointJogForm OpenPoseJointJogForm(
    ITxDevice device,
    Action<object, FormClosedEventArgs> ColseAction,
    TxPose pose = null)
  {
    CUiKinJointJogForm cuiKinJointJogForm = new CUiKinJointJogForm();
    if (TxPose.op_Equality(pose, (ITxObject) null))
    {
      cuiKinJointJogForm.PoseName = CApKinPoseEditorApp.GetUniquePoseName(device);
      cuiKinJointJogForm.PoseNameReadOnly = false;
    }
    else
    {
      cuiKinJointJogForm.PoseName = pose.Name;
      cuiKinJointJogForm.PoseNameReadOnly = !pose.CanBeRenamed;
      CApKinPoseEditorUtils.JumpToPose(pose);
    }
    if (cuiKinJointJogForm.ShowModeless(device, device.CurrentPose, PoseEditorStringTable.NEW_POSE_TITLE))
      ((Form) cuiKinJointJogForm).FormClosed += new FormClosedEventHandler(ColseAction.Invoke);
    else
      cuiKinJointJogForm = (CUiKinJointJogForm) null;
    return cuiKinJointJogForm;
  }

  internal static TxPose CreateNewPose(ITxDevice device, string poseName)
  {
    TxPose newPose = (TxPose) null;
    using (TxPoseCreationData poseCreationData = new TxPoseCreationData(poseName, device.CurrentPose))
    {
      if (device is ITxComponent itxComponent)
      {
        poseCreationData.CreateAtInstance = !itxComponent.IsOpenForModeling;
        newPose = device.CreatePose(poseCreationData);
      }
    }
    return newPose;
  }

  internal static bool CanModifyPose(ITxPose pose) => ((ITxObject) pose).CanBeModified;
}
